import React, { Component } from 'react';
import MyAvatar from './common/MyAvatar';
import ReplyButton from './common/ReplyButton';

class LayerDetails extends Component {

    render() {
        const { layer,f_id } = this.props;
        return (
            <div style={{ marginLeft: 40,width:"78%", marginTop: 0,background:"#EEEEEE",padding:10 }}>
                <MyAvatar
                    author={layer.publisherInfo}
                    time={layer.createTime}
                    xs={12}
                    level={layer.floor}
                    rank={"layer"} />
                <div style={{marginLeft:10,marginTop:10,width:"80%"}}>{layer.belongId === layer.repliedId ? layer.content : " 回复 " + layer.responder_name + ": " + layer.content}</div>
                <ReplyButton xs={11} tips={"回复 "+layer.floor+"#"} belongId={layer.belongId} responder={layer.publisher} replied_lid={layer.l_id}
                type="2" level={this.props.getMaxLevel()+1}  {...this.props} />
            </div>
        );

    }
}

class FloorDetails extends Component {

    getMaxLevel = () => {
        const { floor } = this.props;
        let max = 0;
        if (floor.layer === undefined) {
            return;
        } else {
            for (let i = 0; i < floor.layer.length; i++) {
                if (max < floor.layer[i].level) {
                    max = floor.layer[i].level;
                }
            }
            return max;
        }
    }

    render() {
        const { floor } = this.props;
        if(floor.publisherInfo!=undefined){
            console.log(floor.publisherInfo.name);
        }
        return (
            <div style={{ marginLeft: 10,width:"100%", marginTop: 20,padding:10,borderBottomStyle:"solid",borderBottomWidth:2,borderBottomColor:"#F5F5F5" }}>
                <MyAvatar
                    author={floor.publisherInfo}
                    time={floor.createTime}
                    xs={11}
                    level={floor.floor}
                    rank={"floor"} />
                <div style={{marginLeft:10,marginTop:10}}>{floor.content}</div>
                <ReplyButton xs={10} tips={"回复层主"} belongId={floor.id} repliedId={floor.id} type="2"   {...this.props} />

                {floor.layerList.map(layer => {
                    return <LayerDetails f_id={floor.id} getMaxLevel={this.getMaxLevel} layer={layer} {...this.props}  />
                })}
            </div>
        );
    }
}

export default FloorDetails;